#pragma once

#include <memory>

#include "base/network.h"

namespace xrtc {

class PortAllocator {
public:
    PortAllocator() : m_network_manager(new NetworkManager()) {
        m_network_manager->create_networks();
    }
    
    ~PortAllocator() = default;
    
    // 获取可用网络地址信息列表
    const std::vector<Network*>& get_networks() {
        return m_network_manager->getNetworks();
    }

    void set_port_range(int min_port, int max_port) {
        if (min_port > 0) {
            m_min_port = min_port;
        }

        if (max_port > 0) {
            m_max_port = max_port;
        }
    }
    
    int get_min_port() { return m_min_port; }
    int get_max_port() { return m_max_port; }

private:
    std::unique_ptr<NetworkManager> m_network_manager;
    int m_min_port = 0;
    int m_max_port = 0;
};    

}